/**
 * 
 */
package de.cbf.cam.dsa.tavern.carte.model.persistence;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

import de.cbf.cam.dsa.tavern.carte.model.entities.Meal;
import de.cbf.cam.dsa.tavern.carte.model.persistence.interfaces.IPersisterMeals;
import de.cbf.cam.dsa.tavern.carte.preferences.PreferenceConstants;

/**
 * @author Stefan Alter
 *
 */
public class PersisterXMLMeals extends PersisterAbstractXML implements
		IPersisterMeals {
	private final String[] MEAL_FILTER_SUFFIXES 	= {"*.ml.xml","*.*"};
	private final String[] MEAL_FILTER_NAMES 		= {"Mahlzeitenliste(.ml.xml)","<Alle Dateien>"};
	/**
	 * 
	 */
	public PersisterXMLMeals() {		
	}
	
	/* (non-Javadoc)
	 * @see de.cbf.cam.dsa.tavern.carte.model.persistence.interfaces.IPersisterMeals#getMeals()
	 */
	@Override
	public Collection<Meal> getMeals() {
		Collection<Meal> resultList = new ArrayList<Meal>();
		//search objects for Meals
		Iterator<Object> iterator = getObjects().iterator();
		while (iterator.hasNext()) {
			Object object = (Object) iterator.next();
			if (object instanceof Meal) {
				Meal ingredient = (Meal) object;
				resultList.add(ingredient);
			}
		}
		return resultList;
	}

	/* (non-Javadoc)
	 * @see de.cbf.cam.dsa.tavern.carte.model.persistence.interfaces.IPersisterMeals#setMeals(java.util.Collection)
	 */
	@Override
	public void setMeals(Collection<Meal> meals) {
		setObjects(meals);
	}
	/* (non-Javadoc)
	 * @see de.cbf.cam.dsa.tavern.carte.model.persistence.interfaces.IPersister#getName()
	 */
	@Override
	public String getName() {
		return "Mahlzeiten, XML-basiert";
	}
	/* (non-Javadoc)
	 * @see de.cbf.cam.dsa.tavern.carte.model.persistence.PersisterAbstractXML#getFileDialogText()
	 */
	@Override
	protected String getFileDialogText() {		
		return "Mahlzeitendatei suchen";
	}

	/* (non-Javadoc)
	 * @see de.cbf.cam.dsa.tavern.carte.model.persistence.PersisterAbstractXML#getFilterExtensions()
	 */
	@Override
	protected String[] getFilterExtensions() {		
		return MEAL_FILTER_SUFFIXES;
	}

	/* (non-Javadoc)
	 * @see de.cbf.cam.dsa.tavern.carte.model.persistence.PersisterAbstractXML#getFilterNames()
	 */
	@Override
	protected String[] getFilterNames() {		
		return MEAL_FILTER_NAMES;
	}

	/* (non-Javadoc)
	 * @see de.cbf.cam.dsa.tavern.carte.model.persistence.PersisterAbstract#getEventText()
	 */
	@Override
	protected String getEventText() {
		return "changedMeals";
	}

	/* (non-Javadoc)
	 * @see de.cbf.cam.dsa.tavern.carte.model.persistence.PersisterAbstract#getMessageSaveComplete()
	 */
	@Override
	protected String getMessageSaveComplete() {
		return "Mahlzeiten gespeichert";
	}

	/* (non-Javadoc)
	 * @see de.cbf.cam.dsa.tavern.carte.model.persistence.PersisterAbstract#getMessageLoadComplete()
	 */
	@Override
	protected String getMessageLoadComplete() {
		return "Mahlzeiten geladen";
	}

	@Override
	protected String getPreferenceNameOfFileName() {		
		return PreferenceConstants.P_XML_MEALS_FILE;
	}

}
